// define the namespaces
jmaki.namespace("jmaki.widgets.yahoo.tooltip");

/**
 * Yahoo jMaki Tooltip Widget
 * 
 * This widget uses container overlay to display 
 * 
 * @author: Ahmad M. Zawawi <ahmad.zawawi@gmail.com>
 * @see http://developer.yahoo.com/yui/container/tooltip/index.html
 * @see http://developer.yahoo.com/yui/container/overlay/index.html
 */
jmaki.widgets.yahoo.tooltip.Widget = function(wargs) {
    var topic = '/yahoo/tooltip';
    var self = this;
    var uuid = wargs.uuid;
    
    //read the widget configuration arguments
    var cfg = {
        context: ['tt1','tt2','tt3'],
        text: '<b>Default Tooltip text</b>',
        showDelay:200,
        hidedelay:250,
        effect: undefined
    };
    
    /*
     */
    
    if (typeof wargs.args != 'undefined') {
        //overide topic name if needed
        if (typeof wargs.args.topic != 'undefined') { 
            topic = wargs.args.topic;
        }      
        //Tooltip text [can be HTML]
        if (typeof wargs.args.text != 'undefined') { 
            cfg.text = wargs.args.text;
        }      
        //number of millisecond before showing tooltip
        if (typeof wargs.args.showDelay != 'undefined') { 
            cfg.showDelay = wargs.args.showDelay;
        }      
        //number of millisecond before showing tooltip
        if (typeof wargs.args.hideDelay != 'undefined') { 
            cfg.hideDelay = wargs.args.hideDelay;
        }      
        //animation effect
        if (typeof wargs.args.effect != 'undefined') { 
            var FADE = {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5};
            var SLIDE = {effect:YAHOO.widget.ContainerEffect.SLIDE,duration:0.5};
            switch(wargs.args.effect) {
                case 'FADE':
                    cfg.effect = [FADE]     
                    break;
                case 'SLIDE':
                    cfg.effect = [SLIDE];
                    break;
                case 'BOTH':
                    cfg.effect = [FADE,SLIDE];
                    break;
                case 'NONE':
                default:
                    //none is default
                    cfg.effect = undefined;
            }
        }      
    }
    
    if (typeof wargs.value != 'undefined') {
        //the element or elements to watch for on mouseover
        if (typeof wargs.value.context != 'undefined') { 
            cfg.context = wargs.value.context;
        } 
    }
    
    //create the tooltip and that's it ;-)
    this.tooltip = new YAHOO.widget.Tooltip(uuid,cfg); 
    
} //end of widget